#! /usr/bin/env python
# _*_ coding: utf-8 _*_

import wx
from wx.grid import *

data = (("CF", "Bob", "Dernier"), ("2B", "Ryne", "Sandberg"),
        ("LF", "Gary", "Matthews"), ("1B", "Leon", "Durham"),
        ("RF", "Keith", "Moreland"), ("3B", "Ron", "Cey"),
        ("C", "Jody", "Davis"), ("SS", "Larry", "Bowa"),
        ("P", "Rick", "Sutcliffe"))

class LineupEntry:

    def __init__(self, pos, first, last):
        self.pos = pos
        self.first = first
        self.last = last

class LineupTable(PyGridTableBase):

    colLabels = ("First", "Last")

    colAttrs = ("first", "last")

    def __init__(self, entries):
        PyGridTableBase.__init__(self)
        self.entries = entries

    def GetNumberRows(self):
        return len(self.entries)

    def GetNumberCols(self):
        return 2

    def GetColLabelValue(self, col):
        return self.colLabels[col]

    def GetRowLabelValue(self, row):
        return self.entries[row].pos

    def IsEmpty(self, row, col):
        return False

    def GetValue(self, row, col):
        entry = self.entries[row]
        return getattr(entry, self.colAttrs[col])

    def SetValue(self, row, col, value):
        entry = self.entries[row]
        return setattr(entry, self.colAttrs[col], value)

class SimpleGrid(Grid):

    def __init__(self, parent):
        Grid.__init__(self, parent, wx.NewId())
        entries = []
        for pos, first, last in data:
            entry = LineupEntry(pos, first, last)
            entries.append(entry)
        self.table = LineupTable(entries)

        print self.table.GetNumberCols(), self.table.GetNumberRows()
        print self.table.entries[0].pos
        print self.table.entries[0].first
        print self.table.entries[0].last

        self.SetTable(self.table)

class TestFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.NewId(), 'A Grid', size=(275,275))
        self.grid = SimpleGrid(self)

class App(wx.App):

    def OnInit(self):
        self.frame = TestFrame(None)
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

if __name__ == "__main__":
    app = App()
    app.MainLoop()
